package com.kaikai.test;

import com.aliyun.vod.upload.impl.UploadVideoImpl;
import com.aliyun.vod.upload.req.UploadVideoRequest;
import com.aliyun.vod.upload.resp.UploadVideoResponse;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.vod.model.v20170321.*;
import com.kaikai.commonutils.R;
import com.kaikai.vod.util.AliyunVodSDKUtils;
import com.kaikai.vod.util.ConstantPropertiesUtil;
import com.sun.deploy.net.URLEncoder;
import org.junit.Test;

import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.List;

import static com.kaikai.vod.util.AliyunVodSDKUtils.initVodClient;


/**
 * aliyun.oss.file.endpoint=oss-cn-beijing.aliyuncs.com
 * aliyun.oss.file.keyid=LTAI5tFBfDWQq4Xh7fDXM8TE
 * aliyun.oss.file.keysecret=NK3NYxzKULYqKm17TEKVaaPKfSx00R
 * #bucket可以在控制台创建，也可以使用java代码创建
 * aliyun.oss.file.bucketname=edu1998
 */

public class test {



    public static void main(String[] args) throws ClientException, UnsupportedEncodingException {

        DefaultAcsClient client = initVodClient("LTAI5tFBfDWQq4Xh7fDXM8TE", "NK3NYxzKULYqKm17TEKVaaPKfSx00R");
        GetVideoPlayAuthRequest request = new GetVideoPlayAuthRequest();
        request.setVideoId("37edbdc1ff2045ba8e54ec222fe94278");
        GetVideoPlayAuthResponse response;
        try {
            response = client.getAcsResponse(request);
            //播放凭证
            System.out.print("PlayAuth = " + response.getPlayAuth() + "\n");
            //VideoMeta信息
            System.out.print("VideoMeta.Title = " + response.getVideoMeta().getTitle() + "\n");
            System.out.print("RequestId = " + response.getRequestId() + "\n");
        } catch (Exception e) {
            System.out.print("ErrorMessage = " + e.getLocalizedMessage());
        }

    }

//    static String accessKeyId="LTAI5tFBfDWQq4Xh7fDXM8TE";
//    static String accessKeySecret="NK3NYxzKULYqKm17TEKVaaPKfSx00R";
//
//    //获取视屏上传凭证
//    public static void getAut(){
//
//        DefaultAcsClient client = InitObject.initVodClient(accessKeyId,accessKeySecret);
//
//        GetVideoPlayAuthRequest request=new GetVideoPlayAuthRequest();
//        GetVideoPlayAuthResponse response = new GetVideoPlayAuthResponse();
//
//
//        request.setVideoId("872f108f6e22400b9a71f509924ebdcf");
//        try {
//            response = client.getAcsResponse(request);
//            //播放凭证
//            System.out.print("PlayAuth = " + response.getPlayAuth() + "\n");
//            //VideoMeta信息
//            System.out.print("VideoMeta.Title = " + response.getVideoMeta().getTitle() + "\n");
//        } catch (Exception e) {
//            System.out.print("ErrorMessage = " + e.getLocalizedMessage());
//        }
//        System.out.print("RequestId = " + response.getRequestId() + "\n");
//    }
//    @Test
//    public void uploadVideo(){
//        String title= "yujiankai";
//        String fileName="C:\\Users\\yujiankai\\Videos\\a.mp4";
//        UploadVideoRequest request = new UploadVideoRequest(accessKeyId, accessKeySecret, title, fileName);
//        /* 可指定分片上传时每个分片的大小，默认为2M字节 */
//        request.setPartSize(2 * 1024 * 1024L);
//        /* 可指定分片上传时的并发线程数，默认为1，(注：该配置会占用服务器CPU资源，需根据服务器情况指定）*/
//        request.setTaskNum(1);
//
//        UploadVideoImpl uploader = new UploadVideoImpl();
//        UploadVideoResponse response = uploader.uploadVideo(request);
//        System.out.print("RequestId=" + response.getRequestId() + "\n");  //请求视频点播服务的请求ID
//        if (response.isSuccess()) {
//            System.out.print("VideoId=" + response.getVideoId() + "\n");
//        } else {
//            /* 如果设置回调URL无效，不影响视频上传，可以返回VideoId同时会返回错误码。其他情况上传失败时，VideoId为空，此时需要根据返回错误码分析具体错误原因 */
//            System.out.print("VideoId=" + response.getVideoId() + "\n");
//            System.out.print("ErrorCode=" + response.getCode() + "\n");
//            System.out.print("ErrorMessage=" + response.getMessage() + "\n");
//        }
//    }
}
